home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / nbsamp.arc / NBSEND.C < prev    next >
Text File  |  1992-01-14  |  3KB  |  94 lines

  1. /* NBSEND.C - test of NetBIOS- broadcasts a message - Paul McGinnis   */
  2. /* AST Research, Inc. - Data Comm Support - Dept. 430                 */
  3. /* August 1988. - comments added 9/26/88                              */
  4. /*                                      */
  5. /* General calling sequence for NetBIOS calls:                        */
  6. /* 1. Set up NCB (Network Control Block)                              */
  7. /* 2. Make ES:BX point to NCB structure                               */
  8. /* 3. Load AX with 100h                                               */
  9. /* 4. Generate an INT 5Ch                                             */
  10. /*                                       */
  11. /* NetBIOS commands and definitions in NETBIOS.H                      */
  12. /*                                      */
  13. /* Compilation information:                                           */
  14. /* Compiler: Borland Turbo C v1.5                                     */
  15. /* Memory model: Small                                                */
  16. /* Floating point support: none                                       */
  17.  
  18. #include <dos.h>
  19. #include <stdio.h>
  20. #include <netbios.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24.  
  25. main()
  26. {
  27.   NCB far * send_block;
  28.   char far * send_message;
  29.   char far * session_name;
  30.   unsigned char ret_code, net_num, iflag;
  31.   send_block = (NCB far *) malloc(sizeof(NCB));
  32.   send_message = (char far *) malloc(80);
  33.   session_name = (char far *) malloc(16);
  34.   _AH = 0;
  35.   geninterrupt(0x2a);   /* Check to see if NetBIOS is loaded */
  36.   iflag = _AH;
  37.   if (!iflag)
  38.   {
  39.     puts("    *** ERROR - NetBIOS not installed. ***");
  40.     return;
  41.   }
  42.   printf("Enter session name: ");
  43.   gets(session_name);
  44.   printf("Enter message: ");
  45.   gets(send_message);
  46.   puts("generating network name...");
  47.   send_block -> NCB_COMMAND = ADD_NAME_WAIT;   /* Use default time-out values */
  48.   send_block -> NCB_LANA_NUM = 0;
  49.   send_block -> NCB_STO = 0;
  50.   send_block -> NCB_RTO = 0;
  51.   strncpy(send_block -> NCB_NAME, session_name, 16);  /* Copy name to NCB   */
  52.   strncpy(send_block -> NCB_CALLNAME, "*", 16);  /* Check all names on net  */
  53.   _ES = FP_SEG(send_block);
  54.   _BX = FP_OFF(send_block);
  55.   _AX = 0x100;
  56.   geninterrupt(0x5c);
  57.   ret_code = _AL;
  58.   net_num = send_block -> NCB_NUM;
  59.   if (ret_code)
  60.   {
  61.     printf("Bad return code = %02Xh\n", ret_code);
  62.     return;
  63.   }
  64.   printf("Session established. Name number = %02Xh\n", net_num);
  65.   puts("Broadcasting message...");
  66.   send_block -> NCB_STO = 0;
  67.   send_block -> NCB_BUFFER_OFFSET = FP_OFF(send_message);
  68.   send_block -> NCB_BUFFER_SEGMENT = FP_SEG(send_message);
  69.   send_block -> NCB_LENGTH = strlen(send_message);
  70.   send_block -> NCB_COMMAND = SEND_BCST_DATAGRAM_WAIT; /* Wait for completion */
  71.   _ES = FP_SEG(send_block);
  72.   _BX = FP_OFF(send_block);
  73.   _AX = 0x100;
  74.   geninterrupt(0x5c);
  75.   ret_code = _AL;
  76.   if (ret_code)
  77.     printf("Error number = %02Xh.\n", ret_code);
  78.   else
  79.     puts("Message broadcast successfully");
  80.   printf("Releasing session >>>%Fs<<<, number %02Xh\n",
  81.     send_block -> NCB_NAME, net_num);
  82.   send_block -> NCB_NUM = net_num;
  83.   send_block -> NCB_COMMAND = DELETE_NAME_WAIT; /* Schedule name for removal */
  84.   _ES = FP_SEG(send_block);
  85.   _BX = FP_OFF(send_block);
  86.   _AX = 0x100;
  87.   geninterrupt(0x5c);
  88.   ret_code = _AL;
  89.   if (ret_code)
  90.     printf("Error number = %02Xh.\n", ret_code);
  91.   else
  92.     puts("Completed normally.");
  93. }
  94.